package Panel;

import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import java.util.Iterator;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;

public class LayoutPanel {

	public LayoutPanel(JPanel content){
		
		content.removeAll();
		content.setLayout( new FlowLayout() );
		
		ActionListener actionListener = new ActionListener() {	
			@Override
			public void actionPerformed(ActionEvent e) {
				JFrame w = new JFrame();
				
				for (int i=0; i < 10; i++){
					w.add(new JButton(String.valueOf(i)));
				}
				
				switch(e.getActionCommand()){
				case "GridLayout": 
					w.setLayout( new GridLayout() );
					break;
				case "BorderLayout":
					w.setLayout( new BorderLayout() );
					break;
				case "FlowLayout":
					w.setLayout( new FlowLayout() );
					break;
				case "BoxLayout":
					break;
				}
				w.pack();
				w.setVisible(true);
			}
		};
		
		ArrayList<JButton> buttons = new ArrayList<JButton>();
			buttons.add(new JButton("GridLayout"));
			buttons.add(new JButton("BorderLayout"));
			buttons.add(new JButton("FlowLayout"));
			buttons.add(new JButton("BoxLayout"));
			
		Iterator<JButton> iButtons;
		JButton b;
		
		iButtons = buttons.iterator();
		while ( iButtons.hasNext() ){
			b = (JButton)iButtons.next();
			b.addActionListener(actionListener);
			content.add(b);
		}
	}
}
